package com.guandi.geekbrowser.primary.service.impl;

import com.guandi.geekbrowser.primary.entity.Tab;
import com.guandi.geekbrowser.primary.repository.TabRepository;
import com.guandi.geekbrowser.primary.service.TabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class TabServiceImpl implements TabService {

    @Autowired
    private TabRepository tabRepository;

    @Override
    public List<Tab> findAll() {
        return tabRepository.findAll();
    }

    @Override
    public List<Tab> findByName(String name) {
        return tabRepository.findByName(name);
    }

    @Override
    public Tab findByUserIdAndName(String id, String name) {
        return tabRepository.findByUserIdAndName(id, name);
    }

    @Override
    public void saveTab(Tab tab) {
        tabRepository.save(tab);
    }

    @Override
    public List<Tab> findByUserId(String id) {
        return tabRepository.findByUserId(id);
    }

    @Override
    public List<Tab> findByUserIdAndDel(String id, Boolean del) {
        return tabRepository.findByUserIdAndDel(id, del);
    }

    @Override
    public List<Tab> findByUserIdAndDelAndId(String id, Boolean del, Long did) {
        return tabRepository.findByUserIdAndDelAndId(id, del, did);
    }

    @Override
    public List<Tab> findByUserIdAndDelAndCountry(String id, Boolean del, String country) {
        return tabRepository.findByUserIdAndDelAndCountry(id, del, country);
    }

    @Override
    public void deleteByUserIdAndName(String id, String name) {
        tabRepository.deleteByUserIdAndName(id, name);
    }

    @Override
    public void deleteSafe(Tab tab) {
        tab.setDel(true);
        tabRepository.save(tab);
    }

    @Override
    public Optional<Tab> findById(Long id) {
        return tabRepository.findById(id);
    }

    @Override
    public Tab findByUserIdAndNameAndCountry(String id, String name, String country) {
        return tabRepository.findByUserIdAndNameAndCountry(id, name, country);
    }

    @Override
    public List<Tab> findByUserIdAndCountry(String id, String country) {
        return tabRepository.findByUserIdAndCountry(id, country);
    }

    @Override
    public void deleteByUserIdAndNameAndCountry(String id, String name, String country) {
        tabRepository.deleteByUserIdAndNameAndCountry(id, name, country);
    }

    @Override
    public List<Tab> findByUserIdAndCountryAndType(String id, String country, Integer type) {
        return tabRepository.findByUserIdAndCountryAndType(id, country, type);
    }


}
